package converter;

import com.gitee.feizns.dynamic.convert.Converts;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;

/**
 * @author feizns
 * @since 2019/6/12
 */
public class ConvertDemo {

    public static void main(String[] args) {

        //数字
        byte  q         =   Converts.to(1.1f, byte.class);
        short w         =   Converts.to(1.1, short.class);
        int   e         =   Converts.to(w, int.class);
        long  r         =   Converts.to(e, long.class);
        float t         =   Converts.to(r, int.class);
        double y        =   Converts.to(t, double.class);
        BigDecimal u    =   Converts.to(y, BigDecimal.class);
        BigInteger i    =   Converts.to(u, BigInteger.class);

        //日期
        String date = "2022-12-01 12:12:12.123";
        //Thu Dec 01 12:12:12 CST 2022
        System.out.println(Converts.to(date, Date.class));
        //2022-12-01
        System.out.println(Converts.to(date, java.sql.Date.class));
        //12:12:12
        System.out.println(Converts.to(date, Time.class));
        //2022-12-01 12:12:12.123
        System.out.println(Converts.to(date, Timestamp.class));
        //2022-12-01
        System.out.println(Converts.to(date, LocalDate.class));
        //12:12:12.123
        System.out.println(Converts.to(date, LocalTime.class));
        //2022-12-01T12:12:12.123
        System.out.println(Converts.to(date, LocalDateTime.class));

        System.out.println("年份:");

        //日期
        String year = "2022";
        //Sat Jan 01 00:00:00 CST 2022
        System.out.println(Converts.to(year, Date.class));
        //2022-01-01
        System.out.println(Converts.to(year, java.sql.Date.class));
        //00:00:00
        System.out.println(Converts.to(year, Time.class));
        //2022-01-01 00:00:00.0
        System.out.println(Converts.to(year, Timestamp.class));
        //2022-01-01
        System.out.println(Converts.to(year, LocalDate.class));
        //00:00
        System.out.println(Converts.to(year, LocalTime.class));
        //2022-01-01T00:00
        System.out.println(Converts.to(year, LocalDateTime.class));

        //枚举
        A e1 = Converts.to("A", A.class);//C.A
        B e2 = Converts.to("A", B.class);//C.A

    }

    //enums
    enum A { A }

    enum B { A;
        public static B valueOf(A a) {
            return Enum.valueOf(B.class, a.name());
        }
    }

}
